﻿#region Using namespaces

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Xceed.Wpf.Toolkit.PropertyGrid;
using Xceed.Wpf.Toolkit.PropertyGrid.Editors;

using BOL.Models.Genome;
using BOL.Models.Taxonomy;

#endregion

namespace BOL.Apps.GeneNetworkBrowser.Controls
{
    public partial class CytobandEditor : UserControl, ITypeEditor
    {
        #region Public properties

        public static readonly DependencyProperty ChromosomeProperty =
            DependencyProperty.Register("Chromosome", typeof(Chromosome), typeof(CytobandEditor),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        public static readonly DependencyProperty FromProperty =
            DependencyProperty.Register("From", typeof(int), typeof(CytobandEditor),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        public static readonly DependencyProperty ToProperty =
            DependencyProperty.Register("To", typeof(int), typeof(CytobandEditor),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        public static readonly DependencyProperty LocusStringProperty =
            DependencyProperty.Register("LocusString", typeof(string), typeof(CytobandEditor),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        public static readonly DependencyProperty GieStainStringProperty =
            DependencyProperty.Register("GieStainString", typeof(string), typeof(CytobandEditor),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        public Chromosome Chromosome { get { return (Chromosome)GetValue(ChromosomeProperty); } set { SetValue(ChromosomeProperty, value); } }

        public int From { get { return (int)GetValue(FromProperty); } set { SetValue(FromProperty, value); } }

        public int To { get { return (int)GetValue(ToProperty); } set { SetValue(ToProperty, value); } }

        public string LocusString { get { return (string)GetValue(LocusStringProperty); } set { SetValue(LocusStringProperty, value); } }

        public string GieStainString { get { return (string)GetValue(GieStainStringProperty); } set { SetValue(GieStainStringProperty, value); } }

        #endregion

        #region Constructor

        public CytobandEditor()
        {
            InitializeComponent();
        }

        #endregion

        #region Public methods

        public FrameworkElement ResolveEditor(PropertyItem propertyItem)
        {
            Binding binding = new Binding("Chromosome");
            binding.Source = propertyItem;
            binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
            BindingOperations.SetBinding(this, CytobandEditor.ChromosomeProperty, binding);

            binding = new Binding("From");
            binding.Source = propertyItem;
            binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
            BindingOperations.SetBinding(this, CytobandEditor.FromProperty, binding);

            binding = new Binding("To");
            binding.Source = propertyItem;
            binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
            BindingOperations.SetBinding(this, CytobandEditor.ToProperty, binding);

            binding = new Binding("LocusString");
            binding.Source = propertyItem;
            binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
            BindingOperations.SetBinding(this, CytobandEditor.LocusStringProperty, binding);

            binding = new Binding("GieStainString");
            binding.Source = propertyItem;
            binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
            BindingOperations.SetBinding(this, CytobandEditor.GieStainStringProperty, binding);

            return this;
        }

        #endregion
    }
}
